package com.example.crm.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.crm.dao.CustomerDAO;
import com.example.crm.pojo.Customer;

@WebServlet("/listcustomer")
public class ListCustomerServlet extends HttpServlet
{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		// 1. 
		
		// 2. 调用DAO查询数据 放入请求对象
		CustomerDAO dao = new CustomerDAO();
		try {
			List<Customer> list = dao.findAll();
			req.setAttribute("list", list);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// 3. 请求转发jsp 
		req.getRequestDispatcher("jsp/customer/list.jsp").forward(req, resp);
	
	}

}
